#include <iostream>
using namespace std;

const int buffer = 10; // 缓冲区数

int produce = 0;
int consume = 0;
int n = buffer;

char YesorNot = 0, input;

static void p() {

}

static void v() {

}

void ospv()
{
    cout << "请进行生产/消费操作!" << endl;
    while (1)
    {
        cin >> input;
        if ((input == 'a' || input == 'A') && (n > 0))
        {
            produce++, n--;
            cout << "生产一个产品并已送到缓冲区." << endl;
            continue;
        }
        if ((input == 'B' || input == 'b') && (n < buffer))
        {
            consume++, n++;
            cout << "从缓冲区取走了一个产品并进行消费." << endl;
            continue;
        }
        if (input == 'c' || input == 'C')
            break;

        if (n <= 0)
        {
            cout << "对不起!缓冲区已满!不能进行生产!" << endl;
            continue;
        }
        if (n == buffer)
        {
            cout << "对不起!缓冲区已空!不能进行消费!" << endl;
            continue;
        }
    }
    cout << "是否结束生产/消费操作(Y/N)" << endl;
    cin >> YesorNot;
    if (YesorNot == 'y' || YesorNot == 'Y')
    {
        cout << "此次生产/消费操作结束." << endl;
        cout << "产品生产总数为:" << produce << endl;
        cout << "产品消费总数为:" << consume << endl;
        cout << "缓冲区剩余产品数为:" << produce - consume << endl;
    }
    if (YesorNot == 'n' || YesorNot == 'N')
        ospv();
}

int main()
{
    cout << "键入A/a:  生产一个产品并送到缓冲区." << endl;
    cout << "键入B/b:  从缓冲区取走一个产品并进行消费." << endl;
    cout << "键入C/c:  生产/消费过程结束." << endl;
    ospv();
    return 0;
}